//@ sourceURL=inverstWrite.js 
CommonUtils.regNamespace("com.im.inverstWrite");
com.im.inverstWrite.invoke = function() {
	var param = {
		pageNumber: 1,
		pageSize: 20
	};
    var client = new com.im.common.ajax();
    var operType = "";
    var InverstWrite
    var tmpfiles;//文件上传下载

    function _init() {
    	//重置按钮
    	$('#ResetBtn').click(function (){
    		_resetSearchInfo();
    	});
        //查询按钮
        $("#SearchBtn").click(function(){
        	_loadDataList(true);
        });
        //新增弹出按钮
        $("#addBtn").click(function(){
        	_addInverstWrite();
        });
        $("#saveBtn").click(function(){
        	_saveInverstWrite();
        });
        //查询-建设单位to实施项目
        $("#searchOrgName").project2unit2itemCommpent({
            elmIdPlanTypeSel : "",
            elmIdUnitSel : "searchOrgName",//组织单位下拉元素
            elmIdItemSel : "searchImpleProjName",//实施项目下拉元素
            orgType : "10",//初始化单位时，单位类型
            callbackFunc: function (callBackType, ret) {//下拉框值改变时回调
                _loadDataList();
            }
        });
      //新增编辑-建设单位to实施项目
        $("#orgUnit").project2unit2itemCommpent({
            elmIdPlanTypeSel : "",
            elmIdUnitSel : "orgUnit",//组织单位下拉元素
            elmIdItemSel : "impleProjName",//实施项目下拉元素
            orgType : "10",//初始化单位时，单位类型
            callbackFunc: function (callBackType, ret) {//下拉框值改变时回调
                //_callBackOrg(objvalue, objname);
                //callBackType : 1 所属规划值变更 2单位值变更  3项目名称变更
                //ret: orgId,orgName,impleProjId,impleProjName,planProjClass,planProjClassName
                if(callBackType == 3) {
                    var req = {};
                    req.impleProjId = ret.impleProjId;
                    req.declareType = 10;
                    //var resp = client.callAsJson("investPlanService/queryProjectAndTotalFoundSource", req);
                    var resp = client.callAsJson("investPlanService/queryInvestPlanForGreen", req);
                    if (resp.success) {
                        var fund1 = _getFundDto(resp.result.fundDetailVo,'planProjMoney');
                        var fund2 = _getFundDto(resp.result.fundDetailVo,'implProjMoney');
                        var fund3 = _getFundDto(resp.result.fundDetailVo,'investPlanMoney');
                        var fund4 = _getFundDto(resp.result.fundDetailVo,'fundPlanMoney');
                        $("#buFund1").val(fund1.fundBu);
                        $("#shengFund1").val(fund1.fundSheng);
                        $("#gaoFund1").val(fund1.fundGao);
                        $("#qiFund1").val(fund1.fundQi);
                        $("#shiFund1").val(fund1.fundShi);
                        $("#otherFund1").val(fund1.fundOther);
                        $("#total1").val(fund1.total);

                        $("#buFund2").val(fund2.fundBu);
                        $("#shengFund2").val(fund2.fundSheng);
                        $("#gaoFund2").val(fund2.fundGao);
                        $("#qiFund2").val(fund2.fundQi);
                        $("#shiFund2").val(fund2.fundShi);
                        $("#otherFund2").val(fund2.fundOther);
                        $("#total2").val(fund2.total);

                        $("#buFund3").val(fund3.fundBu);
                        $("#shengFund3").val(fund3.fundSheng);
                        $("#gaoFund3").val(fund3.fundGao);
                        $("#qiFund3").val(fund3.fundQi);
                        $("#shiFund3").val(fund3.fundShi);
                        $("#otherFund3").val(fund3.fundOther);
                        $("#total3").val(fund3.total);

                        $("#buFund4").val(fund4.fundBu);
                        $("#shengFund4").val(fund4.fundSheng);
                        $("#gaoFund4").val(fund4.fundGao);
                        $("#qiFund4").val(fund4.fundQi);
                        $("#shiFund4").val(fund4.fundShi);
                        $("#otherFund4").val(fund4.fundOther);
                        $("#total4").val(fund4.total);
                        //本次投资计划里面的金额，默认剩余的额度
                        $("#buFund").val(fund1.fundBu-fund2.fundBu);
                        $("#shengFund").val(fund1.fundSheng-fund2.fundSheng);
                        $("#gaoFund").val(fund1.fundGao-fund2.fundGao);
                        $("#qiFund").val(fund1.fundQi-fund2.fundQi);
                        $("#shiFund").val(fund1.fundShi-fund2.fundShi);
                        $("#otherFund").val(fund1.fundOther-fund2.fundOther);
                        if(fund1.FundBu-fund2.FundBu < 0){
                            $("#buFund").val(0);
                        }
                        if(fund1.FundSheng-fund2.FundSheng < 0){
                            $("#shengFund").val(0);
                        }
                        if(fund1.FundGao-fund2.FundGao < 0){
                            $("#gaoFund").val(0);
                        }
                        if(fund1.FundQi-fund2.FundQi < 0){
                            $("#qiFund").val(0);
                        }
                        if(fund1.FundShi-fund2.FundShi < 0){
                            $("#shiFund").val(0);
                        }
                        if(fund1.fundOther-fund2.fundOther < 0){
                        	$("#otherFund").val(0);
                        }
                        //合计
                        _initTotal();
                        //剩余值记录为属性，用于判断是否超出预算
                        // $("#buFund").attr("maxVal",fund1.FundBu-fund2.FundBu);
                        // $("#shengFund").attr("maxVal",fund1.FundSheng-fund2.FundSheng);
                        // $("#gaoFund").attr("maxVal",fund1.FundGao-fund2.FundGao);
                        // $("#qiFund").attr("maxVal",fund1.FundQi-fund2.FundQi);
                        // $("#shiFund").attr("maxVal",fund1.FundShi-fund2.FundShi);
                    }
                }
            }
        });
        
      //实施项目
//	    $("#itemBtn").click(function() {
//	        $("#itemBtn").itemSearchCommpent({
//	            elmIdOut : "impleProjName",
//	            elmIdModal : "itemSearchModal",
//	            elmIdOrgModal : "unitSearchModal3",
//	            callbackFunc: function (projectId, projectName) {
//	            	$("#impleProjName").val(projectName).trigger("change");
//	                $("#impleProjId").val(projectId).trigger("change");
//	            }
//	        });
//	    });
        
        //时间插件
//	    $('#startDatepicker,#endDatepicker').datepicker({
//        	startView: 'decade',  
//            minView: 'decade',  
//            format: 'yyyy',  
//            maxViewMode: 2,  
//            minViewMode:2,  
//            autoclose: true 
//        });
        //复选框
        $('input[type="checkbox"].minimal, input[type="radio"].minimal').iCheck({
          checkboxClass: 'icheckbox_minimal-blue',
          radioClass   : 'iradio_minimal-blue'
        });
        //验证
        _formValidator();
        //重置验证
        $('#addEditModal').on('hidden.bs.modal', function() {
        	_reset();
        });

        var req = {};
        req.declareType = 10;
        req.hasYearDt = 'Y';
        var result = client.callAsJson("investPlanService/queryDeclareSetIds", req);
        if (result.success) {
            var investApplyCode = $("#investApplyCode");
            investApplyCode.append("<option value='' selected='selected'>请选择</option>");
            $.each(result.result, function (i, item) {
                investApplyCode.append("<option value='" +  item.declareSetId  + "' year='" + item.yearDt + "' >" + item.declareCode + "</option>");
            });
            var searchDeclareSetName = $("#searchDeclareSetName");
           /* searchDeclareSetName.append("<option value='' selected='selected'>请选择</option>");*/
            $.each(result.result, function (i, item) {
            	searchDeclareSetName.append("<option value='" +  item.declareSetId  + "' year='" + item.yearDt + "' >" + item.declareCode + "</option>");
            });
        }
        $("#searchDeclareSetName").on("change",function(){
        	_loadDataList();
        });
        //下拉框
        $('.select2').select2();

        //加载列表信息
        _initDataList(1);


        //失去聚焦
        $("#buFund").blur(function () {
            _initTotal();
        });
        $("#shengFund").blur(function () {
            _initTotal();
        });
        $("#gaoFund").blur(function () {
            _initTotal();
        });
        $("#qiFund").blur(function () {
            _initTotal();
        });
        $("#shiFund").blur(function () {
            _initTotal();
        });
        $("#otherFund").blur(function () {
            _initTotal();
        });

    };
    //重置搜索条件
    function _resetSearchInfo(){
    	$('#searchOrgName').val("").trigger("change");
        $('#searchImpleProjName').val("").trigger("change");
        $('#searchDeclareSetName').val("").trigger("change");
    }
    //更新数据列表
    function _loadDataList(pageNumber){
        _initDataList(pageNumber);
        // param.declareSetId =  $("#searchDeclareSetName option:selected").attr("value");
        // param.impleProjId =  $("#searchImpleProjName option:selected").attr("value");
        // param.impleProjName =  param.impleProjId == '' ? '' : $("#searchImpleProjName option:selected").html();
        // param.orgId = $("#searchOrgName option:selected").attr("value");
        // param.orgName = param.orgId == '' ? '' : $("#searchOrgName option:selected").html();
        // if(pageNumber){
    		// param.pageNumber = 1;
        //     $('#inverstPlanList').datagrid("load",param);
        // }else{
    	 //   $('#inverstPlanList').datagrid("reload",param);
        // }
    }
    //新增编辑(保存按钮)
    function _saveInverstWrite(){
    	$("#inverstWriteForm").data("bootstrapValidator").validate();
    	var flag = $("#inverstWriteForm").data("bootstrapValidator").isValid();
    	if(flag){
	    	var saveparam={};
            saveparam.declareSetId = $("#investApplyCode").val();
	    	saveparam.investPlanId= $("#investPlanId").val();
	    	saveparam.impleProjId= $("#impleProjName").val();
	    	//saveparam.investPlanCode= $("#investPlanCode").val();
	    	//saveparam.investPlanName= $("#investPlanName").val();
	    	saveparam.fundSourceBu= $("#buFund").val();
	    	saveparam.fundSourceSheng= $("#shengFund").val();
	    	saveparam.fundSourceGao= $("#gaoFund").val();
	    	saveparam.fundSourceQi= $("#qiFund").val();
	    	saveparam.fundSourceShi= $("#shiFund").val();
	    	saveparam.fundSourceOther= $("#otherFund").val();
	    	saveparam.description= $("#description").val();
//	    	saveparam.investPlanStartDt= $("#startDatepicker").val();
//	    	saveparam.investPlanEndDt= $("#endDatepicker").val();
	    	saveparam.staffCode= 1;
	    	var optype=$("#opertype").val();
	    	 if(optype=='mod'){
                 client.callAsFile(tmpfiles.newly, function(fileRes) {
                     if(fileRes.success){
                         saveparam.addFiles = fileRes.result;
                         saveparam.delFiles = tmpfiles.del;
                         var result = client.callAsJson("investPlanService/updateInvestPlan", saveparam);
                         if(result.resultCode=='0'){
                             $("#addEditModal").modal("hide");
                             //新增后发起查询-2018-07-09
                             _loadDataList(true);
                             //_resetSearchInfo();
                         }else {
                             toastr.error("服务器忙！请稍后再试！"+result.resultMsg);
                         }
                     }else{
                         toastr.error('文件服务器忙！请稍后再试！');
                     }
                 });
	    	 }else{
	    	     if(tmpfiles.newly == undefined || tmpfiles.newly.length == 0){
                     var result = client.callAsJson("investPlanService/addInvestPlan", saveparam);
                     if(result.resultCode=='0'){
                         $("#addEditModal").modal("hide");
                         //新增后发起查询-2018-07-09
                         _loadDataList(true);
                         //_resetSearchInfo();
                     }else {
                         toastr.error("服务器忙！请稍后再试！"+result.resultMsg);
                     }
                 }else{
                     client.callAsFile(tmpfiles.newly, function(fileRes) {
                         if(fileRes.success){
                             saveparam.addFiles = fileRes.result;
                             var result = client.callAsJson("investPlanService/addInvestPlan", saveparam);
                             if(result.resultCode=='0'){
                                 $("#addEditModal").modal("hide");
                                 //新增后发起查询-2018-07-09
                                 _loadDataList(true);
                                 //_resetSearchInfo();
                             }else {
                                 toastr.error("服务器忙！请稍后再试！"+result.resultMsg);
                             }
                         }else{
                             toastr.error('文件服务器忙！请稍后再试！');
                         }
                     });
                 }
	    	 }
    	}
    	  
    }
  //验证
    function _formValidator(){
    	$("#inverstWriteForm").bootstrapValidator({
    	    feedbackIcons: {
    	      valid: 'glyphicon glyphicon-ok',
    	      invalid: 'glyphicon glyphicon-remove',
    	      validating: 'glyphicon glyphicon-loadData'
    	    },
    	    excluded: [':hidden', ':not(:visible)'],
    	    fields: {
    	    	// investPlanName:{
    	    	// 	validators: {
  	    	  //         notEmpty: {
  	    	  //           message: '投资计划名称不能为空'
  	    	  //         }
  	    	  //       }
    	    	// },
    	    	impleProjName: {
    	            trigger:"change",
	    	        validators: {
	    	          notEmpty: {
	    	            message: '实施项目名称不能为空'
	    	          }
	    	        }
    	    	},
                orgUnit: {
                    trigger:"change",
                    validators: {
                        notEmpty: {
                            message: '建设单位不能为空'
                        }
                    }
                },
                investApplyCode: {
                    trigger:"change",
                    validators: {
                        notEmpty: {
                            message: '投资计划申报编码不能为空'
                        }
                    }
                },
//    	    	startDt: {
//    	            trigger:"change",
//	    	        validators: {
//	    	          notEmpty: {
//	    	            message: '开工年不能为空'
//	    	          }
//	    	        }
//    	    	},
//    	    	endDt: {
//    	            trigger:"change",
//	    	        validators: {
//	    	          notEmpty: {
//	    	            message: '完工年不能为空'
//	    	          },
//	                  callback: {
//	                	  message: "完工日期不能小于开工日期", 
//	                	  callback:function(value, validator,$field){
//	                        if($("#startDatepicker").val() == null || $("#startDatepicker").val() == "" ||  $("#endDatepicker").val() == null||  $("#endDatepicker").val() == ""){
//	                            return true;
//	                        }
//	                        return new Date($("#startDatepicker").val()) < new Date($("#endDatepicker").val());
//	                	  }
//	    	          }
//	    	        }
//    	    	},
    	    	buFund: {
	    	        validators: {
	    	          notEmpty: {
	    	            message: '部补助'
	    	          },
	    	          regexp: {
                          regexp: /^\d+(\.\d+)?$/,
                          message: '只能包含数字/小数点'
                      }
	    	        }
    	    	},
    	    	shengFund: {
	    	        validators: {
	    	          notEmpty: {
	    	            message: '省财政'
	    	          },
	    	          regexp: {
                          regexp: /^\d+(\.\d+)?$/,
                          message: '只能包含数字/小数点'
                      }
	    	        }
    	    	},
    	    	gaoFund: {
	    	        validators: {
	    	          notEmpty: {
	    	            message: '政府融资'
	    	          },
	    	          regexp: {
                          regexp: /^\d+(\.\d+)?$/,
                          message: '只能包含数字/小数点'
                      }
	    	        }
    	    	},
    	    	qiFund: {
	    	        validators: {
	    	          notEmpty: {
	    	            message: '企业自筹'
	    	          },
	    	          regexp: {
                          regexp: /^\d+(\.\d+)?$/,
                          message: '只能包含数字/小数点'
                      }
	    	        }
    	    	},
    	    	shiFund: {
	    	        validators: {
	    	          notEmpty: {
	    	            message: '市州配套'
	    	          },
	    	          regexp: {
                          regexp: /^\d+(\.\d+)?$/,
                          message: '只能包含数字/小数点'
                      }
	    	        }
    	    	}
    	    }
    	  });
    }
    //重置验证
    function _reset(){
    	$("#inverstWriteForm").data('bootstrapValidator').destroy();
        $('#inverstWriteForm').data('bootstrapValidator', null);
        _formValidator();
    }
    //新增操作
    function _addInverstWrite(index){
    	 $("#addEditModal .modal-title").html("投资计划填报增加");
    	 _showInverstWrite();
         $("#addEditModal").modal("show");
    }
    //编辑操作
    function _modInverstWrite(index){
    	 $("#addEditModal .modal-title").html("投资计划填报修改");
    	 InverstWrite = $('#inverstPlanList').datagrid('getData').rows[index];
    	  var result = client.callAsJson("investPlanService/queryInvestPlanDetail", {'investPlanId': InverstWrite.investPlanId});
    	  if (result.resultCode=="0") {
              if(result.result!= null){
            	  _showInverstWrite(result.result);
              }
          } else {
              toastr.error("服务器忙！请稍后再试！"+result.resultMsg);
          }
         $("#addEditModal").modal("show");
    }
    //删除操作
    function _delInverstWrite(index){
    	com.im.common.confirm("确认是否删除", null, function () {
    		InverstWrite = $('#inverstPlanList').datagrid('getData').rows[index];
    	   	var result = client.callAsJson("investPlanService/updateInvestPlan", {'investPlanId':InverstWrite.investPlanId,'statusCd':'70'});
    	   	if (result.resultCode=='0') {
    	   		_loadDataList();
    	    }else {
    	    	toastr.error("服务器忙！请稍后再试！"+result.resultMsg);
    	    }
        });
   }
    function _showInverstWrite(InverstWrite){
    	if(InverstWrite==null){
    		//文件
            var file = new com.im.common.file();
            tmpfiles = file.activate(1);
            $('#investApplyCode').val($('#investApplyCode option:eq(1)').attr('value')).trigger("change").attr('disabled',false);
            $('#orgUnit').val($('#orgUnit option:eq(1)').attr('value')).trigger("change").attr('disabled',false);
            $('#impleProjName').val($('#impleProjName option:eq(1)').attr('value')).trigger("change").attr('disabled',false);
			$("#opertype").val("add");
            $("#investPlanId").val("");

            $("#impleProjId").val("");
//             $("#startDatepicker").val("");
//             $("#endDatepicker").val("");
            $("#buFund").val("");
            $("#shengFund").val("");
            $("#gaoFund").val("");
            $("#qiFund").val("");
            $("#shiFund").val("");
            $("#otherFund").val("");
            $("#total").val("");

            $("#buFund1").val("");
            $("#shengFund1").val("");
            $("#gaoFund1").val("");
            $("#qiFund1").val("");
            $("#shiFund1").val("");
            $("#otherFund1").val("");
            $("#total1").val("");

            $("#buFund2").val("");
            $("#shengFund2").val("");
            $("#gaoFund2").val("");
            $("#qiFund2").val("");
            $("#shiFund2").val("");
            $("#otherFund2").val("");
            $("#total2").val("");

            $("#buFund3").val("");
            $("#shengFund3").val("");
            $("#gaoFund3").val("");
            $("#qiFund3").val("");
            $("#shiFund3").val("");
            $("#otherFund3").val("");
            $("#total3").val("");

            $("#buFund4").val("");
            $("#shengFund4").val("");
            $("#gaoFund4").val("");
            $("#qiFund4").val("");
            $("#shiFund4").val("");
            $("#otherFund4").val("");
            $("#total4").val("");
            //$("#orgUnit").val("").trigger("change");
            var tmpOrgId = $("#orgUnit").find("option:eq(1)").val();
            $("#orgUnit").val(tmpOrgId).trigger("change");
            //$("#investApplyCode").val("").trigger("change");

            //var result = client.callAsJson("commonService/getSeq", {'tableName':'T_INVEST_PLAN'});
    		 //$("#investPlanCode").val(result.result.seq);
             //$("#investPlanName").val("");
            var tmpImpleId = $("#impleProjName").find("option:eq(1)").val();
            if(tmpImpleId == undefined){
                $("#impleProjName").val("").trigger("change");
                $("#impleProjName").attr('projectid',"");
            }else{
                $("#impleProjName").val(tmpImpleId).trigger("change");
                $("#impleProjName").attr('projectid',tmpImpleId);
            }

        }else{
    		$("#opertype").val("mod");
    		 $("#investPlanId").val(InverstWrite.investPlanId);
    		 //$("#investPlanCode").val(InverstWrite.investPlanCode);
             //$("#investPlanName").val(InverstWrite.investPlanName);
             $("#impleProjName").attr('projectid',InverstWrite.impleProjId);
             $("#impleProjId").val(InverstWrite.impleProjId);
//             $("#startDatepicker").val(InverstWrite.investPlanStartDt);
//             $("#endDatepicker").val(InverstWrite.investPlanEndDt);

            $("#investApplyCode").val(InverstWrite.declareSetId).trigger("change").attr('disabled',true);
            $("#orgUnit").val(InverstWrite.orgId).trigger("change").attr('disabled',true);
            $("#impleProjName").val(InverstWrite.impleProjId).trigger("change").attr('disabled',true);

            //文件
            var file = new com.im.common.file();
            var fileList = InverstWrite.files;
            $.each(fileList,function (index,item){
            	fileList[index].fileSuffix = item.attachFullName;
            	fileList[index].uploadName = item.attachFullName;
            	fileList[index].filePath = item.attachPath;
            });
            tmpfiles = file.activate(1, fileList);

            var req = {};
            req.impleProjId = InverstWrite.impleProjId;
            req.declareType = 10;
            //var resp = client.callAsJson("investPlanService/queryProjectAndTotalFoundSource", req);
            var resp = client.callAsJson("investPlanService/queryInvestPlanForGreen", req);
            //if (resp.success) {
            var fund1 = _getFundDto(resp.result.fundDetailVo,'planProjMoney');
            var fund2 = _getFundDto(resp.result.fundDetailVo,'implProjMoney');
            var fund3 = _getFundDto(resp.result.fundDetailVo,'investPlanMoney');
            var fund4 = _getFundDto(resp.result.fundDetailVo,'fundPlanMoney');
            var fund = _getFundDto(resp.result.fundDetailVo,'fundWriteMoney');

            $("#buFund1").val(fund1.fundBu);
            $("#shengFund1").val(fund1.fundSheng);
            $("#gaoFund1").val(fund1.fundGao);
            $("#qiFund1").val(fund1.fundQi);
            $("#shiFund1").val(fund1.fundShi);
            $("#otherFund1").val(fund1.fundOther);
            $("#total1").val(fund1.total);

            $("#buFund2").val(fund2.fundBu);
            $("#shengFund2").val(fund2.fundSheng);
            $("#gaoFund2").val(fund2.fundGao);
            $("#qiFund2").val(fund2.fundQi);
            $("#shiFund2").val(fund2.fundShi);
            $("#otherFund2").val(fund2.fundOther);
            $("#total2").val(fund2.total);

            $("#buFund3").val(fund3.fundBu);
            $("#shengFund3").val(fund3.fundSheng);
            $("#gaoFund3").val(fund3.fundGao);
            $("#qiFund3").val(fund3.fundQi);
            $("#shiFund3").val(fund3.fundShi);
            $("#otherFund3").val(fund3.fundOther);
            $("#total3").val(fund3.total);

            $("#buFund4").val(fund4.fundBu);
            $("#shengFund4").val(fund4.fundSheng);
            $("#gaoFund4").val(fund4.fundGao);
            $("#qiFund4").val(fund4.fundQi);
            $("#shiFund4").val(fund4.fundShi);
            $("#otherFund4").val(fund4.fundOther);
            $("#total4").val(fund4.total);
            //本次投资计划里面的金额，默认剩余的额度
//            $("#buFund").val(fund.fundBu);
//            $("#shengFund").val(fund.fundSheng);
//            $("#gaoFund").val(fund.fundGao);
//            $("#qiFund").val(fund.fundQi);
//            $("#shiFund").val(fund.fundShi);
//            $("#otherFund").val(fund.fundOther);
            $("#buFund").val(InverstWrite.buFund);
            $("#shengFund").val(InverstWrite.shengFund);
            $("#gaoFund").val(InverstWrite.gaoFund);
            $("#qiFund").val(InverstWrite.qiFund);
            $("#shiFund").val(InverstWrite.shiFund);
            $("#otherFund").val(InverstWrite.otherFund);
            $("#Total").val(InverstWrite.total);
            $("#description").val(InverstWrite.description);
            //}
    	}
    }
    //初始化表格数据
    function _initDataList(pNumber){
        //var d = new Date();
        //var vYear = d.getFullYear();
        param.pageNumber = pNumber;
        var vYear = $("#searchDeclareSetName option:selected").attr("year");

    	var columns=[[
    	    {field:'序号',title:"序号",width:$(this).width()*0.03,fitColumns:true,rowspan:2,
    	        formatter: function(value,row,index){
    	             return  index+1;
    	        }
    	    },
//    	    {field:'investPlanCode',title:"投资计划编码",fitColumns:true,rowspan:2},
    	    {field:'declareSetName',title:"投资计划申报批次",fitColumns:true,rowspan:2,align:'center'},
    	    {field:'impleProjName',title:"实施项目名称",fitColumns:true,rowspan:2,align:'center'},
            {field:'orgName',title:"建设单位",fitColumns:true,rowspan:2,align:'center'},
            {field:'JSNX',title:"建设年限",fitColumns:true,align:'center',colspan:2,},
            {field:'preWorkSituation',title:"前期工作情况",fitColumns:true,align:'center',rowspan:2,},
            {field:'GSTZ',colspan:7,title:'概算总投资（单位：万元）',align:'center'},
            {field:'XDDJH',colspan:7,title:'累计至'+(vYear )+'年下达的计划（单位：万元）',align:'center'},
            {field:'TZDZJ',colspan:7,title:'累计至'+(vYear )+'年完成的投资（单位：万元）',align:'center'},
            {field:'DWDZJ',colspan:7,title:'累计至'+(vYear )+'年到位的资金（单位：万元）',align:'center'},
            {field:'TZJH',colspan:7,title:''+(vYear)+'年填报投资计划（单位：万元）',align:'center'},
            {field:'files',title:"填报附件",rowspan:2,width:100,fitColumns:true,formatter: function(value,row,index){
                if(value.length > 0){
                    var fileNames = "";
                    $.each(value, function (i, item) {
                        fileNames += item.attachFullName + "  ";
                    });
                    return fileNames;
                }else {
                    return "";
                }
            }},
    	    {field:'description',title:"备注",width:$(this).width()*0.1,fitColumns:true,rowspan:2,align:'center'},
    	    {field:'statusName',title:"状态",width:$(this).width()*0.06,fitColumns:true,rowspan:2},
    	    {field:'operation',title:"操作",width:$(this).width()*0.06,rowspan:2,
    	         formatter: function(value,row,index){

    	            if(row.statusCd == '40' || row.statusCd == '60'){
                        //已初审、已批复不能修改
                        return '';
                    }else{

                        return  '<a href="javascript:; "onclick="com.im.inverstWrite.invoke.modInverstWrite(\''+index+'\')" title="修改"><i class="fa fa-edit"></i></a> '+
                            '<a href="javascript:; "onclick="com.im.inverstWrite.invoke.delInverstWrite(\''+index+'\')" title="删除"><i class="fa fa-trash"></i></a>';

                    }
	         }
    	    }],
            [{field:'investPlanStartDt',title:"开工年",fitColumns:true},
             {field:'investPlanEndDt',title:"完工年",fitColumns:true},
                {field:'total',title:"合计",fitColumns:true
                    ,formatter: function(value,row,index){
                        return _getColVal(row,'total','planProjMoney');
                    }
                },
                {field:'buFund',title:"部补助",fitColumns:true
                    ,formatter: function(value,row,index){
                        return _getColVal(row,'fundBu','planProjMoney');
                    }
                },
                {field:'shengFund',title:"省财政",fitColumns:true
                    ,formatter: function(value,row,index){
                        return _getColVal(row,'fundSheng','planProjMoney');
                    }
                },
                {field:'gaoFund',title:"政府融资",fitColumns:true
                    ,formatter: function(value,row,index){
                        return _getColVal(row,'fundGao','planProjMoney');
                    }
                },
                {field:'shiFund',title:"市州配套",fitColumns:true
                    ,formatter: function(value,row,index){
                        return _getColVal(row,'fundShi','planProjMoney');
                    }
                },
                {field:'qiFund',title:"企业自筹",fitColumns:true
                    ,formatter: function(value,row,index){
                        return _getColVal(row,'fundQi','planProjMoney');
                    }
                },
                {field:'otherFund',title:"其他",fitColumns:true
                    ,formatter: function(value,row,index){
                        return _getColVal(row,'fundOther','planProjMoney');
                    }
                },
             {field:'total1',title:"合计",fitColumns:true
                 ,formatter: function(value,row,index){
                     return _getColVal(row,'total','implProjMoney');
                 }
             },
    	     {field:'buFund1',title:"部补助",fitColumns:true
                 ,formatter: function(value,row,index){
                     return _getColVal(row,'fundBu','implProjMoney');
                 }
             },
			 {field:'shengFund1',title:"省财政",fitColumns:true
                 ,formatter: function(value,row,index){
                     return _getColVal(row,'fundSheng','implProjMoney');
                 }
             },
			 {field:'gaoFund1',title:"政府融资",fitColumns:true
                 ,formatter: function(value,row,index){
                     return _getColVal(row,'fundGao','implProjMoney');
                 }
             },
			 {field:'shiFund1',title:"市州配套",fitColumns:true
                 ,formatter: function(value,row,index){
                     return _getColVal(row,'fundShi','implProjMoney');
                 }
             },
                {field:'qiFund1',title:"企业自筹",fitColumns:true
                    ,formatter: function(value,row,index){
                        return _getColVal(row,'fundQi','implProjMoney');
                    }
                },
                {field:'otherFund1',title:"其他",fitColumns:true
                    ,formatter: function(value,row,index){
                        return _getColVal(row,'fundOther','implProjMoney');
                    }
                },
                {field:'total2',title:"合计",fitColumns:true
                    ,formatter: function(value,row,index){
                        return _getColVal(row,'total','investPlanMoney');
                    }
                },
                {field:'buFund2',title:"部补助",fitColumns:true
                    ,formatter: function(value,row,index){
                        return _getColVal(row,'fundBu','investPlanMoney');
                    }
                },
                {field:'shengFund2',title:"省财政",fitColumns:true
                    ,formatter: function(value,row,index){
                        return _getColVal(row,'fundSheng','investPlanMoney');
                    }
                },
                {field:'gaoFund2',title:"政府融资",fitColumns:true
                    ,formatter: function(value,row,index){
                        return _getColVal(row,'fundGao','investPlanMoney');
                    }
                },
                {field:'shiFund2',title:"市州配套",fitColumns:true
                    ,formatter: function(value,row,index){
                        return _getColVal(row,'fundShi','investPlanMoney');
                    }
                },
                {field:'qiFund2',title:"企业自筹",fitColumns:true
                    ,formatter: function(value,row,index){
                        return _getColVal(row,'fundQi','investPlanMoney');
                    }
                },
                {field:'otherFund2',title:"其他",fitColumns:true
                    ,formatter: function(value,row,index){
                        return _getColVal(row,'fundOther','investPlanMoney');
                    }
                },
                {field:'total3',title:"合计",fitColumns:true
                    ,formatter: function(value,row,index){
                        return _getColVal(row,'total','fundPlanMoney');
                    }
                },
                {field:'buFund3',title:"部补助",fitColumns:true
                    ,formatter: function(value,row,index){
                        return _getColVal(row,'fundBu','fundPlanMoney');
                    }
                },
                {field:'shengFund3',title:"省财政",fitColumns:true
                    ,formatter: function(value,row,index){
                        return _getColVal(row,'fundSheng','fundPlanMoney');
                    }
                },
                {field:'gaoFund3',title:"政府融资",fitColumns:true
                    ,formatter: function(value,row,index){
                        return _getColVal(row,'fundGao','fundPlanMoney');
                    }
                },
                {field:'shiFund3',title:"市州配套",fitColumns:true
                    ,formatter: function(value,row,index){
                        return _getColVal(row,'fundShi','fundPlanMoney');
                    }
                },
                {field:'qiFund3',title:"企业自筹",fitColumns:true
                    ,formatter: function(value,row,index){
                        return _getColVal(row,'fundQi','fundPlanMoney');
                    }
                },
                {field:'otherFund3',title:"其他",fitColumns:true
                    ,formatter: function(value,row,index){
                        return _getColVal(row,'fundOther','fundPlanMoney');
                    }
                },
                {field:'total0',title:"合计",fitColumns:true
                    ,formatter: function(value,row,index){
                        return _getColVal(row,'total','fundWriteMoney');
                    }
                },
                {field:'buFund0',title:"部补助",fitColumns:true
                    ,formatter: function(value,row,index){
                        return _getColVal(row,'fundBu','fundWriteMoney');
                    }
                },
                {field:'shengFund0',title:"省财政",fitColumns:true
                    ,formatter: function(value,row,index){
                        return _getColVal(row,'fundSheng','fundWriteMoney');
                    }
                },
                {field:'gaoFund0',title:"政府融资",fitColumns:true
                    ,formatter: function(value,row,index){
                        return _getColVal(row,'fundGao','fundWriteMoney');
                    }
                },
                {field:'shiFund0',title:"市州配套",fitColumns:true
                    ,formatter: function(value,row,index){
                        return _getColVal(row,'fundShi','fundWriteMoney');
                    }
                },
                {field:'qiFund0',title:"企业自筹",fitColumns:true
                    ,formatter: function(value,row,index){
                        return _getColVal(row,'fundQi','fundWriteMoney');
                    }
                },
                {field:'otherFund0',title:"其他",fitColumns:true
                    ,formatter: function(value,row,index){
                        return _getColVal(row,'fundOther','fundWriteMoney');
                    }
                }
			 ]
		];
		param.staffCode=1;
        param.declareSetId =  $("#searchDeclareSetName option:selected").attr("value");
        param.impleProjId =  $("#searchImpleProjName option:selected").attr("value");
        param.impleProjName =  param.impleProjId == '' ? '' : $("#searchImpleProjName option:selected").html();
        param.developOrg = $("#searchOrgName option:selected").attr("value");
        param.orgName = param.orgId == '' ? '' : $("#searchOrgName option:selected").html();
        param.statusCd = '30';
    	$('#inverstPlanList').datagrid({
            url:'/InfoManageWeb/investPlanService/queryInvestPlanList',
           // url:'/InfoManageWeb/investPlanService/queryInvestPlanTrialList',
    	    method:'post',
    	    dataType : 'json',
    	    queryParams:param,
    	    pagination:true,
    	    nowrap:false,
    	    fitColumns:true,
    	    columns:columns,
    	    loadMsg:'数据加载中，请耐心等待',
    	    onBeforeLoad : function(param){
	    	    for (var key in param) {
		    	    if(key=="rows"){
		    	    	delete param[key];
		    	    }
		    	}
    	    },
    	    loadFilter:function(data){
    	      if(data.resultCode!=0){
    	        toastr.error(data.resultCode);
    	        return null;
    	      }else{
    	        return data.result;
    	      }
    	    },
    	});
    	var p = $('#inverstPlanList').datagrid('getPager');
    	  $(p).pagination({
    	    pageSize: 20,
    	    pageList: [10,20,30],
    	    beforePageText: '第',
    	    afterPageText: '页    共 {pages}  页',
    	    displayMsg: '当前显示 {from} - {to} 条记录 共 {total}  条记录',
    	    onSelectPage:function(pageNumber, pageSize){
    	      param.pageNumber=pageNumber;
    	      param.pageSize=pageSize;
    	    	var impleProjName = $("#searchImpleProjName").val();
    	        var declareSetId =  $("#searchDeclareSetName option:selected").attr("value");
    	        var orgId = $("#searchOrgName option:selected").attr("value");
    	    	var orgName = orgId == '' ? '' : $("#searchOrgName option:selected").html();
    	        param.impleProjName = impleProjName;
    	        param.declareSetId = declareSetId;
    	        param.orgName = orgName;
    	        param.orgId = orgId;
    	      $('#inverstPlanList').datagrid('reload',param);
    	    }
    	  });
    }
    //数据类型
    //sourceValue,源数据
    //colName,列名
    //type,资金计划类型
    function _getColVal(sourceValue,colName,type){

        var val;
        $.each(sourceValue.fundDetailVo,function (i,obj) {
            if(obj.type  == type){
                val = obj[colName];
                return false;
            }
        });

        if(val == undefined || val == ''){
            val = '0';
        }
        return val;

    };
    //sourceValue,源数据
    //colName,列名
    //type,资金计划类型
    function _getFundDto(sourceValue,type){

        var val;
        $.each(sourceValue,function (i,obj) {
            if(obj.type  == type){
                val = obj;
                return false;
            }
        });

        if(val == undefined || val == ''){
            val = {};
            val.type =  type;
            val.total = '0';
            val.fundBu = '0';
            val.fundSheng = '0';
            val.fundGao = '0';
            val.fundShi = '0';
            val.fundQi = '0';
            val.fundOther = '0';
            //val.statusCd;
            //val.remark;
            //val.fileName;
        }
        return val;

    };
    
    function _initTotal() {

        var b = $("#buFund").val();
        var s = $("#shengFund").val();
        var g = $("#gaoFund").val();
        var q = $("#qiFund").val();
        var sh = $("#shiFund").val();
        var o= $("#otherFund").val();

        var tmp = 0;
        if(!isNaN(b)){
            tmp = tmp + parseFloat(b);
        }
        if(!isNaN(s)){
            tmp = tmp + parseFloat(s);
        }
        if(!isNaN(g)){
            tmp = tmp + parseFloat(g);
        }
        if(!isNaN(q)){
            tmp = tmp + parseFloat(q);
        }
        if(!isNaN(sh)){
            tmp = tmp + parseFloat(sh);
        }
        if(!isNaN(o)){
            tmp = tmp + parseFloat(o);
        }
        $("#Total").val(tmp.toFixed(2));
    }

	return {
		init : _init,
		delInverstWrite : _delInverstWrite,
        modInverstWrite : _modInverstWrite
	}
}();

$(function() {
	com.im.inverstWrite.invoke.init();
});
